import { Action, createReducer, on } from '@ngrx/store';
import { SetModalType, SetModalVisible, SetUserId } from '../actions/member.actions';

export enum ModalTypes{
  Register = 'register',
  LoginByPhone = 'loginByPhone',
  Share = 'share',
  Like = 'like',
  Default = 'default'

}
export type MemberState = {
  modalVisible: boolean;
  modalType: ModalTypes;
  userId: string
}


export const initialState: MemberState = {
  modalVisible: false,
  modalType: ModalTypes.Default,
  userId: ''
}

const reducer = createReducer(
    initialState,
    on(SetModalVisible, (state:any, { modalVisible }) => ({ ...state, modalVisible })),
    on(SetModalType, (state:any, { modalType }) => ({ ...state, modalType })),
    on(SetUserId, (state:any, { id }) => ({ ...state, userId: id })),
);

export function memberReducer(state: MemberState | undefined,action:Action){
    return reducer(state,action);
}


